Shape = class()



plusa = 0
plusb = 0
plusu = ""
plusawn = 0

suba = 0
subb = 0
subu = ""
subawn = 0

multa = 0
multb = 0
multu = ""
multawn = 0

diva = 0
divb = 0
divc = 0
divd = 0
divu = ""
divawn = 0

start = 0

timercount = 15

boxselect = 40

correct = 0
check = 0


adda = 0
subtracta = 0
multiplya = 0
dividea = 0

test = 0

function Shape:init(x, y, image)
    self.xpos = x
    self.ypos = y
    self.pic = image
 
end
 

function Shape:paint(gc)
    gc:drawImage(self.pic, self.xpos, self.ypos)
end

function Shape:setxy(newx, newy)
    if newx > xmin and newx < xmax and newy > ymin and newy < ymax then
        self.xpos = newx
        self.ypos = newy
   end
end
 

function Shape:move(dx, dy)
    local newx,newy
    self:setxy(self.xpos + dx,self.ypos + dy)
end

xmin = 00
ymin = 00
xmax = 320
ymax = 250


function on.paint(gc)

timer.start(1)

gc:setColorRGB(224, 224, 224)
    
    gc:fillRect(xmin, ymin, xmax-xmin+15, ymax-ymin+15)
    

   
   
    

gc:setColorRGB(0, 0, 0)

    gc:setFont("sansserif" , "r", 6)
    gc:drawString("By David Paquette",235,210)
     gc:setFont("sansserif" , "r",12)
    gc:drawString("Math Practice Game",10,20)
    gc:drawString("Time Remaining:",178,20)
    gc:drawString(timercount,300,20)
   
   
    if start == 0
    then
    
    gc:drawString("Press Esc To Start New Game",50,50)
    gc:setFont("sansserif" , "r",9)
    gc:drawString("Use UP and Down Arrow to Select Box",25,150)
    gc:drawString("Press Enter to Check ALL Answers",25,170)
    gc:drawString("or Wait for timer to run out",25,190)
    
    platform.window:invalidate()
    end
    
    platform.window:invalidate()
    
    if start == 1
    then
    
        gc:setColorRGB(255, 255, 255)
    gc:setFont("sansserif" , "r", 11)
gc:fillRect(230, 40,40,20)
gc:fillRect(230, 80,40,20)
gc:fillRect(230, 120,40,20)
gc:fillRect(230, 160,40,20)


gc:setColorRGB(255, 255, 102)
gc:fillRect(230, boxselect,40,20)

gc:setColorRGB(0, 0, 0)

    gc:drawString("1." ,20,55)
    gc:drawString(plusa ,60,55)
    gc:drawString("+",100,55)
    gc:drawString(plusb ,140,55)
  gc:drawString("=" ,180,55)
   gc:drawString(plusu ,230,58)
   
   gc:drawString("2." ,20,95)
       gc:drawString(suba ,60,95)
    gc:drawString("-",100,95)
    gc:drawString(subb ,140,95)
  gc:drawString("=" ,180,95)
  gc:drawString(subu ,230,98)
   
gc:drawString("3." ,20,135)
    gc:drawString(multa ,60,135)
    gc:drawString("x",100,135)
    gc:drawString(multb ,140,135)
  gc:drawString("=" ,180,135)
  gc:drawString(multu ,230,138)
  
   
gc:drawString("4." ,20,175)
    gc:drawString(diva ,60,175)
    gc:drawString("/",100,175)
    gc:drawString(divb ,140,175)
  gc:drawString("=" ,180,175)
  gc:drawString(divu ,230,178)
   
   

   

platform.window:invalidate()

    
   


end

if start == 2
then
 gc:drawString("Press Esc To Start New Game",50,100)
  gc:setColorRGB(0, 153, 0)
 gc:drawString("You Got Them All Right!",70,60)
 platform.window:invalidate()

end

if start == 3
then
 gc:drawString("Press Esc To Start New Game",50,90)
 gc:setColorRGB(153, 0, 0)
 gc:drawString("You Got Some Wrong",80,60)
  gc:setFont("sansserif" , "r", 10)
 if adda == 0
 then
 gc:drawString("1." ,20,115)
    gc:drawString(plusa ,60,115)
    gc:drawString("+",100,115)
    gc:drawString(plusb ,140,115)
  gc:drawString("=" ,180,115)
   gc:drawString(plusawn ,230,118)
   end
   if subtracta == 0
   then
   gc:drawString("2." ,20,130)
       gc:drawString(suba ,60,130)
    gc:drawString("-",100,130)
    gc:drawString(subb ,140,130)
  gc:drawString("=" ,180,130)
  gc:drawString(subawn ,230,133)
  end 
  if multiplya == 0
  then
  
gc:drawString("3." ,20,145)
    gc:drawString(multa ,60,145)
    gc:drawString("x",100,145)
    gc:drawString(multb ,140,145)
  gc:drawString("=" ,180,145)
  gc:drawString(multawn ,230,145)
  end
   
   if dividea == 0
   then
gc:drawString("4." ,20,160)
    gc:drawString(diva ,60,160)
    gc:drawString("/",100,160)
    gc:drawString(divb ,140,160)
  gc:drawString("=" ,180,160)
  gc:drawString(divawn ,230,160)
end
 platform.window:invalidate()

end


if timercount <= 0
then

if test < 4
then
start = 3
end

 if test == 4
 then
start = 2
end
 

end


if tonumber(subu) == subawn
then
subtracta = 1
end

if tonumber(plusu) == plusawn
then
adda = 1
end

if tonumber(multu) == multawn
then
multiplya = 1
end

if tonumber(divu) == divawn
then
dividea = 1
end

test = adda + multiplya + dividea +subtracta 
end

function on.timer()
 if timercount > 0 and start == 1
    then
timercount = timercount - 1
end
 	timer.stop()
 	platform.window:invalidate()
 end

function on.arrowLeft()
   
end
 
function on.arrowRight()

end

    
   


function on.tabKey()

  boxselect = boxselect + 40
if boxselect > 160
then
boxselect = 40
end
platform.window:invalidate()
end


function on.arrowUp()

  boxselect = boxselect - 40
if boxselect < 40
then
boxselect = 160
end
 platform.window:invalidate()
end
function on.arrowDown()

  boxselect = boxselect + 40
if boxselect > 160
then
boxselect = 40
end
 platform.window:invalidate()
end


function on.escapeKey()

plusa = 0
plusb = 0
plusu = ""

suba = 0
subb = 0
subu = ""

multa = 0
multb = 0
multu = ""

diva = 0
divb = 0
divc = 0
divd = 0
divu = ""

   plusa = math.random(50)
   plusb = math.random(50)
   plusawn = plusa + plusb
   
   suba = math.random(50,100)
  subb = math.random(50)
  subawn = suba - subb
  
   multa = math.random(12)
  multb = math.random(12)
  multawn = multa * multb
  
   divc = math.random(12)
  divd = math.random(12)
  
   
   diva = divc * divd
   divb = divc
   divawn = diva / divb
   timercount = 15
boxselect = 40
   test = 0
start = 1


adda = 0
subtracta = 0
multiplya = 0
dividea = 0


platform.window:invalidate()

    end
    
    
    
    function on.charIn(char)
if boxselect == 40
then
plusu = plusu..char
end

if boxselect == 80
then
subu = subu..char
end

if boxselect == 120
then
multu = multu..char
end

if boxselect == 160
then
divu = divu..char
end


platform.window:invalidate()

end



function on.enterKey()


if tonumber(subu) == subawn
then
subtracta = 1
end

if tonumber(plusu) == plusawn
then
adda = 1
end

if tonumber(multu) == multawn
then
multiplya = 1
end

if tonumber(divu) == divawn
then
dividea = 1
end

test = adda + multiplya + dividea +subtracta 
if test < 4
then
start = 3
end

 if test == 4
 then
start = 2
end

end
    

